﻿using ERP.ERPSystem.ProductionSystem;
using ERP.ERPSystem.ProductionSystem.Dto;
using ERP.Team.ProductionSystem;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace ERP.Web.Controllers.ProductionSystem
{
    /// <summary>
    /// 生产系统-设备管理-维修单-xzc
    /// </summary>
    public class RepairOrdersController : Controller
    {
        private readonly IRepairOrdersServices _irepairorderservices;

        public RepairOrdersController(IRepairOrdersServices irepairorderservices)
        {
            _irepairorderservices = irepairorderservices;
        }
        /// <summary>
        /// 维修单视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ShowRepair()
        {
            return View();
        }
        /// <summary>
        /// 查询维修单
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Repair>> GetRepair(GetRepairDto getrepairdto)
        {
            return await _irepairorderservices.GetRepair(getrepairdto);
        }
        /// <summary>
        /// 添加维修单视图
        /// </summary>
        /// <returns></returns>
        public IActionResult AddShowRepairView()
        {
            return View();
        }
        /// <summary>
        /// 添加维修单
        /// </summary>
        /// <param name="repairdto"></param>
        /// <returns></returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<int> AddRepair(RepairDto repairdto)
        {
            var i = await _irepairorderservices.AddRepair(repairdto);
            return i;
        }
        /// <summary>
        /// 更新维修单视图
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateShowRepairView()
        {
            return View();
        }
        /// <summary>
        /// 更新维修单
        /// </summary>
        /// <param name="repairdto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateRepair(RepairDto repairdto)
        {
            var i = await _irepairorderservices.UpdateRepair(repairdto);
            return i;
        }
        /// <summary>
        /// 通过id查询到相关维修单的数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<Repair>> FindRepair(int id)
        {
            return await _irepairorderservices.FindRepair(id);
        }
        /// <summary>
        /// 删除维修单
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteRepair(int id)
        {
            await _irepairorderservices.DeleteRepair(id);
        }
        /// <summary>
        /// 批量删除维修单
        /// </summary>
        /// <param name="ids">要删除的维修单ID列表</param>
        /// <returns>删除成功的数量</returns>
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<int> BatchDeleteRepair(List<int> ids)
        {
            return await _irepairorderservices.BatchDeleteRepair(ids);
        }
    }
}
